package com.spring.blog.pojo.response;

import com.spring.blog.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result {
    //定义统一的返回结果
//    private ResultCodeEnum code;
    private int code;
    private String errMsg;
    private Object data;
    public static Result success(Object data){
        Result result=new Result();
//        result.setCode(ResultCodeEnum.SUCCESS);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setData(data);
        return result;
    }
    public static Result fail(String errMsg){
        Result result=new Result();
//        result.setCode(ResultCodeEnum.FAIL);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        return result;
    }
    //失败，结果可能也有数据传来
    public static Result fail(String errMsg,Object data){
        Result result=new Result();
//        result.setCode(ResultCodeEnum.FAIL);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

}
